/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;
import com.soa.exception.GlobalException;
import com.soa.service.BaseService;
import static com.soa.service.BaseService.getSession;
import com.soa.util.SystemUtil;
import com.soa.util.tccgl.TccglUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * S40001 检查用户是否绑定
 *
 * @author lianzuotai
 */
@Service
public class CheckBindAuth extends BaseService {

    private final Logger log = LoggerFactory.getLogger(CheckBindAuth.class);
    @Resource
    private TccglUtil tccglUtil;

    @Override
    public String[] keys() {
        return null;
    }

//  get_wx_user_auth=select * from pl_user where openid=?
    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inHead, AbstractCommonData out, AbstractCommonData outHead) {
        AbstractCommonData ses = getSession(in);
        String userid = ses.getStringValue("userid");
        String rklx = in.getStringValue("rklx");
        //通过openid 检查用户是否绑定
        AbstractCommonData user = queryData("get_wx_user_auth", new Object[]{userid});
        if (user == null) {
            out.putStringValue("view", "/wx/auth/bind");        //用户未绑定，进入绑定页面
            out.putStringValue("rklx", rklx);
        } else {
            if(!ses.containsKey("user")){
                user.remove("password");
                ses.putAll(user);
            }
            if ("ss".equals(rklx)) {//收树记账
                //查询花木类型
                List<AbstractCommonData> list = queryList("query_hmlx", new Object[]{"hmlx"});
                //查询工地
                List<AbstractCommonData> list_gd = queryList("query_hmlx", new Object[]{"hmysgd"});
                out.putArrayValue("hmlx", list);
                out.putArrayValue("gd", list_gd);
                out.putStringValue("view", "/wx/ss_index");        //用户已绑定，进入收树记账主页
            }else if("fsk".equals(rklx)){//付树款
                
                out.putStringValue("view", "/wx/fsk_index");
            }else if("yc".equals(rklx)){//工地用车
                //查询工地车辆
                List<AbstractCommonData> list = queryList("query_gd_cl", new Object[]{"cph"});
                out.putArrayValue("cl", list);
                out.putStringValue("view", "/wx/yc_index");
            }else if("wdyc".equals(rklx)){//我的用车
                //查询还未归还的用车
                List<AbstractCommonData> list = queryList("query_wgh_yc", new Object[]{userid});
                List<AbstractCommonData> list_ = new ArrayList<AbstractCommonData>();
                for (int i = 0; i < list.size(); i++) {
                    AbstractCommonData abc = list.get(i);
                    abc.putStringValue("cph_", SystemUtil.getColValueDesc("jz_gdyc.cph", abc.getStringValue("cph")));
                    list_.add(abc);
                }
                out.putArrayValue("cl", list_);
                out.putStringValue("view", "/wx/wgh_index");
            }else if("kzjl".equals(rklx)){//开支记录
                //查询工地
                List<AbstractCommonData> list_gd = queryList("query_hmlx", new Object[]{"hmysgd"});
                //查询花销项
                List<AbstractCommonData> list_hx = queryList("query_hmlx", new Object[]{"hxxm"});
                out.putArrayValue("gd", list_gd);
                out.putArrayValue("hx", list_hx);
                out.putStringValue("view", "/wx/rckz");
            }else if("ryjz".equals(rklx)){//人员借支
                out.putStringValue("view", "/wx/ryjz");
            }

        }

    }
}
